home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr05 / makecard.zip / MAKECARD.BAS next >
BASIC Source File  |  1993-07-06  |  3KB  |  91 lines

  1. REM Program to create Cardfile from ASCII text file.
  2. DEFINT A-Z
  3. DIM index$(100), text$(1100), strttxt(100), lentxt(100), numlin(100)
  4. numcard = 1
  5. numtxt = 1
  6. strttxt(1) = 0
  7. null$ = CHR$(0)
  8. crlf$ = CHR$(13) + CHR$(10)
  9. CLS
  10.    LINE INPUT "Name of input file? ", filein$
  11.    OPEN filein$ FOR INPUT AS #1
  12.    LINE INPUT "Name of output file?", fileout$
  13.    OPEN fileout$ FOR OUTPUT AS #2
  14. 10 LINE INPUT #1, index$(numcard)
  15. ' Strip off the asterisk from the index line
  16. 20 temp$ = RIGHT$(index$(numcard), LEN(index$(numcard)) - 1)
  17.    index$(numcard) = temp$
  18. ' If the index line is short, pad it out with blanks 
  19. IF LEN(index$(numcard)) < 40 THEN index$(numcard) = index$(numcard) + STRING$(40 - LEN(index$(numcard)), " ")
  20. ' Get the text lines
  21. 30 LINE INPUT #1, text$(numtxt)
  22. '  check to see if another index line
  23. IF LEFT$(text$(numtxt), 1) = "*" THEN GOTO 40
  24. ' check to see if there are more than 11 lines 
  25. IF numlin(numcard) < 11 THEN 35
  26.    PRINT
  27.    PRINT "WARNING: The following card has more than 11 lines:"
  28.    PRINT "(extra lines ignored)"
  29.    PRINT
  30.    PRINT index$(numcard)
  31.    PRINT
  32.    GOTO 30
  33. ' increment the character count for all the text for this entry
  34. 35 lentxt(numcard) = lentxt(numcard) + LEN(text$(numtxt)) + 2
  35.  ' increment the number of lines for this entry
  36.    numlin(numcard) = numlin(numcard) + 1
  37.    IF EOF(1) THEN GOTO 90
  38.    numtxt = numtxt + 1
  39. ' return for more lines
  40.    GOTO 30
  41. 40 strttxt(numcard + 1) = strttxt(numcard) + lentxt(numcard) + 4
  42. ' calculate the starting position of the text and increment the # of cards 
  43.    numcard = numcard + 1
  44.    index$(numcard) = text$(numtxt)
  45.    GOTO 20
  46. '
  47. ' write .CRD file
  48. 90 PRINT #2, "MGC"; CHR$(numcard); CHR$(0);
  49.    PRINT
  50.    LINE INPUT "Do you want to have the cards sorted alphabetically? (Y/N, RETURN=Y)", ans$
  51.    IF LEFT$(ans$, 1) = "n" OR LEFT$(ans$, 1) = "N" GOTO 99
  52. ' simple sort routine 
  53.    PRINT "Sorting . . ."
  54.    FOR i = 1 TO numcard - 1
  55.    FOR j = i TO numcard
  56.    IF index$(i) < index$(j) GOTO 95
  57.    temp$ = index$(j)
  58.    index$(j) = index$(i)
  59.    index$(i) = temp$
  60.    temp = strttxt(j)
  61.    strttxt(j) = strttxt(i)
  62.    strttxt(i) = temp
  63. 95 NEXT j
  64.    NEXT i
  65. ' end sort routine
  66. 99   FOR i = 1 TO numcard
  67. ' adjust pointer to start of text based on # of cards 
  68.    strttxt(i) = strttxt(i) + 5 + numcard * 52
  69.    st = strttxt(i)
  70. '  convert to least significant byte first format 
  71.    msb = INT(st / 256)
  72.    lsb = st - msb * 256
  73.    PRINT #2, STRING$(6, null$); CHR$(lsb); CHR$(msb); null$; null$; null$; index$(i); null$;
  74.    NEXT i
  75.    k = 0
  76.    FOR i = 1 TO numcard
  77.       msb = INT(lentxt(i) / 256)
  78.       lsb = lentxt(i) - msb * 256
  79.       PRINT #2, null$; null$; CHR$(lsb); CHR$(msb);
  80.      FOR j = 1 TO numlin(i)
  81.      PRINT #2, text$(j + k); crlf$;
  82.      NEXT j
  83.      k = k + numlin(i)
  84.    NEXT i
  85.    CLOSE #1
  86.    CLOSE #2
  87.    SYSTEM
  88.  
  89.  
  90.  
  91.